<?php

declare(strict_types=1);

namespace Modules\Member\Models;

use Catch\Base\CatchModel as Model;
use Illuminate\Database\Eloquent\Casts\Attribute;

/**
 * @property $id
 * @property $name
 * @property $description
 * @property $status
 * @property $creator_id
 * @property $created_at
 * @property $updated_at
 * @property $deleted_at
 */
class MembersWithdraw extends Model
{
    protected $table = 'members_withdraw';

    protected $fillable = ['id','user_id', 'money', 'status', 'account','real_name','type', 'created_at','out_biz_no', 'updated_at', 'deleted_at'];
    protected $appends = ['status_text'];
    public array $searchable = [
        'status' => '=',
        'real_name' => 'like',
        'user_id' => '=',
        'account' => '=',
        'type' => '=',
    ];

    protected array $fields = ['id','user_id', 'money', 'status', 'account', 'real_name','type','created_at','out_biz_no', 'updated_at', 'deleted_at'];
    public $timestamps = true;

    public function user()
    {
        return $this->belongsTo(Members::class,'user_id')->select(['id','avatar','username','mobile','real_name','user_level']);
    }

    public function statusText(): Attribute
    {
        return  Attribute::make(
            get: fn ($value,$attributes) => match ($attributes['status']) {
                '0' => '未审核',
                '1' => '成功',
                '2' => '失败',
                default => '未知',
            }
        );
    }


}
